Error Description and Number Properties Example

The following code opens a read-only ODBC cursor connection against the SQL Server "SEQUEL" and includes a simple error handler that displays the error description and number.

Sub MakeConnection()
Dim rdoCn As New rdoConnection
On Error GoTo CnEh
With rdoCn
    .Connect = "UID=;PWD=;Database=WorkDB;" _
        & "Server=SEQUEL;Driver={SQL Server}" _
        & "DSN='';"
    .LoginTimeout = 5
    .CursorDriver = rdUseODBC
    .EstablishConnection rdDriverNoPrompt, True
End With
AbandonCn:
Exit Sub

CnEh:
Dim er As rdoError
Dim msg as string
    Msg = "An error occured " _
    & "while opening the connection:" _
    & Err & " - " & Error & VbCr
    For Each er In rdoErrors
        Msg = Msg & er.Description  _
         & ":" & er.Number & VbCr
    Next er
    Resume AbandonCn
End Sub